<script>
import { Sales, SalesAll, Saledeleete } from "@/api/link.js"

import { mapState } from "vuex"
export default {
    data() {
        return {
            // tableData: [
            //     {
            //         id: "1",
            //         orderid: 'HG898789',
            //         proid: "https://img1.baidu.com/it/u=3411904551,2690224694&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1675357200&t=ff09ac487f800acf2b03e41ea9ed3634",
            //         proname: '卫衣',
            //         oriprice: "2000",
            //         disprice: "1000",
            //         Creamount: "11",
            //         bnum: "1",
            //         apayprice: "122元",
            //         createime: "2021-07-08 11:09:08",
            //         state: "售后通过",
            //         operation: "售后中"
            //     },
            //     {
            //         id: "2",
            //         orderid: 'HG898789',
            //         proid: "https://img1.baidu.com/it/u=3411904551,2690224694&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1675357200&t=ff09ac487f800acf2b03e41ea9ed3634",
            //         proname: '卫衣',
            //         oriprice: "2000",
            //         disprice: "1000",
            //         Creamount: "11",
            //         bnum: "1",
            //         apayprice: "122元",
            //         createime: "2021-07-08 11:09:08",
            //         state: "售后通过",
            //         operation: "处理售后"
            //     },
            //     {
            //         id: "3",
            //         orderid: 'HG898789',
            //         proid: "https://img1.baidu.com/it/u=3411904551,2690224694&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1675357200&t=ff09ac487f800acf2b03e41ea9ed3634",
            //         proname: '卫衣',
            //         oriprice: "2000",
            //         disprice: "1000",
            //         Creamount: "11",
            //         bnum: "1",
            //         apayprice: "122元",
            //         createime: "2021-07-08 11:09:08",
            //         state: "售后通过",
            //         operation: "处理售后"
            //     },
            //     {
            //         id: "4",
            //         orderid: 'HG898789',
            //         proid: "https://img1.baidu.com/it/u=3411904551,2690224694&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1675357200&t=ff09ac487f800acf2b03e41ea9ed3634",
            //         proname: '卫衣',
            //         oriprice: "2000",
            //         disprice: "1000",
            //         Creamount: "11",
            //         bnum: "1",
            //         apayprice: "122元",
            //         createime: "2021-07-08 11:09:08",
            //         state: "售后通过",
            //         operation: "处理售后"
            //     },
            //     {
            //         id: "5",
            //         orderid: 'HG898789',
            //         proid: "https://img1.baidu.com/it/u=3411904551,2690224694&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1675357200&t=ff09ac487f800acf2b03e41ea9ed3634",
            //         proname: '卫衣',
            //         oriprice: "2000",
            //         disprice: "1000",
            //         Creamount: "11",
            //         bnum: "1",
            //         apayprice: "122元",
            //         createime: "2021-07-08 11:09:08",
            //         state: "售后通过",
            //         operation: "处理售后"
            //     },
            //     {
            //         id: "6",
            //         orderid: 'HG898789',
            //         proid: "https://img1.baidu.com/it/u=3411904551,2690224694&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1675357200&t=ff09ac487f800acf2b03e41ea9ed3634",
            //         proname: '卫衣',
            //         oriprice: "2000",
            //         disprice: "1000",
            //         Creamount: "11",
            //         bnum: "1",
            //         apayprice: "122元",
            //         createime: "2021-07-08 11:09:08",
            //         state: "售后通过",
            //         operation: "处理售后"
            //     },
            // ],
            dialogTableVisible: false,
            dialogFormVisible: false,
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
          
            formLabelWidth: '120px',
            current: 1,
            size: 5,
            listtotal: 0
        }
    },
    computed: {
        ...mapState(['text']),
    },
    methods: {
        // 分装列表的函数
        // ...mapMutations(['UPTEXTA']),
        //分装列表
        checkout() {
            Sales(this.current, this.size).then((res) => {
                // console.log(res.data.records);<<<<<<< HEAD
                // this.UPTEXTA(res.data.data.records)

                // this.UPTEXTA(res.data..records)

                this.$store.commit("UPTEXTA", res.data.records)
            })
        },
        //封装列表的总条数
        SaAll() {
            SalesAll().then((res) => {
                if (res.code == 200) {

                    //  console.log(res.data.total);

                    //  console.log(res.data.data.total);

                    this.listtotal = res.data.total
                }
            })
        },
        //页码事件
        Change(num) {
            // console.log(num);
            Sales(num, this.size).then((res) => {
                // console.log(res.data.records);

                this.$store.commit("UPTEXTA", res.data.records)

            })
        },
        //删除事件
        handleClick(i) {
            // console.log("删除事件", i);
            this.$confirm('此操作将永久删除, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                Saledeleete(i).then(() => {
                    // console.log(res);
                    this.checkout()
                })
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        //处理售后事件
        determine() {
            // console.log(1);
           console.log(this.form.region);
           console.log(this.form.name);
           this.form.region='',
           this.form.name=''
        },

    },




    mounted() {

        this.checkout(),
        this.SaAll()
        // Sales(this.current, this.size).then((res) => {
        //         // console.log(res.data.data.records);
        //         // this.UPTEXTA(res.data.data.records)
        //         this.$store.commit("UPTEXTA", res.data.records)
        //     })

        // Promise.all([Sales(this.current, this.size), SalesAll()]).then((res) => {
        //     console.log(res[0].data.data.records);
        //     this.$store.commit("UPTEXTA", res[0].data.data.records)
        //     this.listtotal = res[1].data.data.total
        // })
    }
}
</script>
<template>
    <div class="box">
        <el-table :data="this.text" border style="width: 100%" :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ 'text-align': 'center' }">
            <!-- <el-table-column prop="afoid" label="序号" width="40px">
            </el-table-column> -->
            <el-table-column prop="afoid" label="订单编号" width="100px">
            </el-table-column>
            <el-table-column prop="afimgurl" label="商品图片">
                <template slot-scope="scope">
                    <img :src="scope.row.afimgurl" alt="">
                </template>
            </el-table-column>
            <el-table-column prop="afproname" label="商品名称">
            </el-table-column>
            <el-table-column prop="aforiprice" label="原价(元)">
            </el-table-column>
            <el-table-column prop="afdisprice" label="折扣价(元)">
            </el-table-column>
            <el-table-column prop="afcreamount" label="积分抵扣金额(元)">
            </el-table-column>
            <el-table-column prop="afbnum" label="购买数量">
            </el-table-column>
            <el-table-column prop="afapayprice" label="实际支付金额(元)">
            </el-table-column>
            <el-table-column prop="afcreatetime" label="创建时间" width="150px">
            </el-table-column>
            <el-table-column prop="state" label="状态" width="100px">
            </el-table-column>

            <el-table-column prop="operation" label="操作" width="150px">
                <template slot-scope="scope">
                    <el-button @click="handleClick(scope.row.afoid)" type="text" size="small">删除</el-button>
                    <el-button type="text" size="small" @click="dialogFormVisible = true">处理售后</el-button>
                </template>
            </el-table-column>
        </el-table>

        <el-pagination background layout="prev, pager, next" :total="this.listtotal" :page-size="5"
            @current-change="Change($event)">
        </el-pagination>

        <el-dialog title="处理售后" :visible.sync="dialogFormVisible">
            <el-form :model="form">

                <el-form-item label="处理意见" :label-width="formLabelWidth">
                    <el-select v-model="form.region" placeholder="请选择">
                        <el-option label="同意" value="同意"></el-option>
                        <el-option label="不同意" value="不同意"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注" :label-width="formLabelWidth" style="margin-left: -5px;">
                    <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogFormVisible = false" @click.stop=determine()>确 定</el-button>
            </div>
        </el-dialog>

    </div>
</template>



<style scoped >
.box {
    width: 100%;
    height: 100%;

}

.el-table .warning-row {
    background: oldlace;
}

.el-table .success-row {
    background: #f0f9eb;
}



.cell img {
    width: 100%;
}
</style>